package main

import (
	"os"
	"strconv"
	"sync"
	//"time"
	"distributed-database/node"
	rpcc "distributed-database/rpcPackage"
)

func main() {
	// 注册所有要通过RPC传输的类型
	// time.Sleep(5 * time.Second)
	rpcc.RegisterTypes()

	// 从命令行参数获取节点配置
	nodeID, err := strconv.Atoi(os.Args[1])
	if err != nil {
		panic(err)
	}

	addr, err := strconv.Atoi(os.Args[2])
	if err != nil {
		panic(err)
	}
	address := "localhost:" + strconv.Itoa(addr)

	var wg sync.WaitGroup
	wg.Add(1)

	// 启动节点
	n := node.StartNode(nodeID)

	// 启动RPC服务器
	node.StartNodeRPCServer(n, address)

	// 等待直到程序被终止
	wg.Wait()
}
